﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UTSDAL.LINQSQL.Model;

namespace UTSDAL.LINQSQL.DAO
{
    public class CourseDayDAO:GenericDAO<CourseDay,Guid>
    {
        public override List<CourseDay> selectAll()
        {
            var courseDaysVar = from courseday in base.selectAll()
                                orderby courseday.DisplayOrder ascending
                                select courseday;

            return courseDaysVar.ToList<CourseDay>();
                                
        }

        public CourseDay findByCourseDayName(String courseDayName)
        {
            var courseDay = from courseday in base.Context.CourseDays
                            where courseday.CourseDayName.Equals(courseDayName)
                            select courseday;

            return courseDay.Single<CourseDay>();
        }

        public List<CourseDay> getEnabledCourseDays()
        {
            var enableCourseDaysVar = from courseday in selectAll()
                                      where courseday.Enabled == true
                                      select courseday;

            return enableCourseDaysVar.ToList<CourseDay>();
        }


        public Boolean isLastDayOfWeekForCourse(CourseDay day)
        {

            List<CourseDay> days = getEnabledCourseDays();

            CourseDay lastDay = days.ElementAt(days.Count - 1);

            return (day.Equals(lastDay));

        }
    }
}
